<?php
class Orders extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organizations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'orders';
	}
	
	public function relations()
	{
		return array(
			'auction'=>array(self::BELONGS_TO, "Auctions", "auction_ID"),
			'user'=>array(self::BELONGS_TO, "Users", "user_ID"),
			'status'=>array(self::BELONGS_TO, "Status", "status_ID"),
		);
	}
	
	public function rules()
	{
		return array(
		/*	array('user_ID, auction_ID', 'unique', 'criteria' => array('select'=>$this->tableName(),
															'condition' => 'user_ID=:user_ID and auction_ID=:auction_ID and status_ID='.AuctionStatus::$OPEN,
															'params'=>array(':user_ID'=>$this->user_ID, ':auction_ID'=>$this->auction_ID)
															),*/
			array('auction_ID', 'unique', 'criteria' => array('select'=>$this->tableName(),
															'condition' => 'auction_ID=:auction_ID and status_ID='.AuctionStatus::$OPEN,
															'params'=>array(':auction_ID'=>$this->auction_ID)
															),
														),
			array('buyer_gross_gallons, buyer_net_gallons', 'required', 'on'=>'buyer-update'),
			array('supplier_gross_gallons, supplier_net_gallons', 'required', 'on'=>'supplier-update'),
			array('buyer_gross_gallons, buyer_net_gallons, supplier_gross_gallons, supplier_net_gallons', 'numerical', 'numberPattern'=>'/^\d{1,9}+(\.\d{1,6})?$/', 
					//	'message'=>'the gallon field at most has 9 digits before the decimal point and 6 digits after the decimal point',
						'on'=>'buyer-update, supplier-update'
						),

		);
	}
}
?>
